/**
 * 
 */
package org.acompanhamento.dao;

import java.util.List;

import org.acompanhamento.domain.Sprint;
import org.acompanhamento.domain.Team;
import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import bancosys.tec.persist.dao.BaseDAO;
import bancosys.tec.persist.hibernate.RestrictionsUtils;
import bancosys.tec.utils.date.Date;

/**
 * @author icaro
 *
 */
public class SprintDAO extends BaseDAO<Sprint>{

	public List<Sprint> findByStartDateEndDateTeam(Date startDate, Date endDate, Team team){
		Criteria criteria = this.createCriteria();

		RestrictionsUtils.addRestrictionEq(criteria, "team", team);

		if(startDate != null && endDate != null){
			Criterion restrictionStart = Restrictions.between("start", startDate, endDate);
			Criterion restrictionEnd = Restrictions.between("end", startDate, endDate);
			criteria.add(Restrictions.or(restrictionStart, restrictionEnd));
		}
		criteria.addOrder(Order.desc("end"));
		return this.executeQuery(criteria);
	}

	public List<Sprint> findByTeam(Team team){
		Criteria criteria = this.createCriteria();

		criteria.add(Restrictions.eq("team", team));

		criteria.addOrder(Order.desc("end"));
		return this.executeQuery(criteria);
	}
}
